package com.chao.ClientSocket;

import java.io.*;
import java.net.Socket;

public class SocketWrite {
    static  final String SERVER="dict.org";
    static final int PORT=2628;

    public static void main(String[] args) throws IOException {
        Socket socket=new Socket(SERVER,PORT);
        socket.setSoTimeout(15000);
        OutputStream out=socket.getOutputStream();
        Writer writer=new OutputStreamWriter(out,"UTF-8");
        writer=new BufferedWriter(writer);
        InputStream in=socket.getInputStream();
        BufferedReader reader=new BufferedReader(
          new InputStreamReader(in,"UTF-8")
        );
        writer.write("DEFINE eng-lat silver" +"\r\n");
        writer.flush();
        for(String line=reader.readLine();line!=null;line=reader.readLine()){
            if(line.startsWith("250")) return;
            else if(line.startsWith("552")) System.out.println("无法找到");
            else if(line.matches("\\d\\d\\d .*")) continue;
            else if(line.trim().equals(".")) continue;
            else System.out.println(line);
        }
        writer.write("quit\r\n");
        writer.flush();
        socket.close();

    }
}
